package xfuzzy.alg_genetico.indeterminado.stop;

import xfuzzy.xfghl.algorithm.ResultGA;

public class GenerationsWithoutImprovement extends StopCondition {
	
	private int numGeneraciones;
	private double value;
	private int counter;
	
	public GenerationsWithoutImprovement(int numGeneraciones)  {
		
		this.numGeneraciones = numGeneraciones;
		this.value = 0.0;
		this.counter = 0;
	}

	public boolean parar(ResultGA conf) {
		
		if (this.value == conf.getBest())
			this.counter++;
		else  {
			this.counter = 0;
			this.value = conf.getBest();
		}
	
		if (this.counter >= numGeneraciones)
			return true;
		return false;
	}

	public int getNumGeneraciones() {
		return numGeneraciones;
	}

	public void setNumGeneraciones(int numGeneraciones) {
		this.numGeneraciones = numGeneraciones;
	}
}
